*****************************************************************
*** Do file to generate the data for the counterfactual analysis (WhatIf in R).
***
*** Created: 7-29-14
*** Modified: 3-6-18
***
*****************************************************************

*** Set working directory
*cd ""

*****************************************************************
*** Ways and Weeks (2014, AJPS): Table 1, page 714
*****************************************************************
use "Way and Weeks 2014\WayWeeksAJPS.dta", clear

*** Table 1 (page 714)
btscs pursueonly year ccode, g(time)
gen time2=time*time
gen time3=time2*time

xtlogit pursueonly persdumjlw_lag land gdppercap time time2 time3, nolog
keep if e(sample)

keep persdumjlw_lag land gdppercap time time2 time3
order persdumjlw_lag land gdppercap time time2 time3
saveold "Way and Weeks 2014\Data\Counterfactuals\WW.dta", replace version(12)

* Counterfactual #1: mean for all (inconsistent values of t)
preserve
	collapse (median) persdumjlw_lag (mean) land gdppercap time - time3
	
	order persdumjlw_lag land gdppercap time time2 time3
	
	tempfile cf1
	save `cf1', replace
restore

* Counterfactual #2: mean for all (consistent values of t)
preserve
	collapse (median) persdumjlw_lag (mean) land gdppercap time - time3
	
	replace time2 = time ^ 2
	replace time3 = time ^ 3
	
	order persdumjlw_lag land gdppercap time time2 time3	
	
	tempfile cf2
	save `cf2', replace 
restore

* Counterfactual #3: median values of t (consistent across t)
preserve
	collapse (median) persdumjlw_lag time - time3 (mean) land gdppercap
	
	order persdumjlw_lag land gdppercap time time2 time3	
	
	tempfile cf3
	save `cf3', replace 
restore

* Counterfactual #4: modal values of t (consistent across t)
preserve
	collapse (median) persdumjlw_lag (mean) land gdppercap time - time3
	
	replace time = 0
	replace time2 = 0
	replace time3 = 0

	order persdumjlw_lag land gdppercap time time2 time3	
	
	tempfile cf4
	save `cf4', replace 
restore

preserve
	use `cf1', clear
	foreach n of numlist 2(1)4 {
		append using `cf`n''
	}
	saveold "Way and Weeks 2014\Data\Counterfactuals\WW_CF.dta", replace version(12)
restore


*****************************************************************
*** Cunningham (2013, AJPS), Table 3, Model 2, page 667
*****************************************************************
use "Cunningham 2013\CunninghamAJPS.dta", clear

logit acdcivilwar1 logfactions prevconcessions_l democracy kin yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw , robust cluster(kgcid)
keep if e(sample)

keep logfactions prevconcessions_l democracy kin yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw
order logfactions prevconcessions_l democracy kin yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw
saveold "Cunningham 2013\Data\Counterfactuals\C.dta", replace version(12)

sum yrsnocivilwar, det
tab yrsnocivilwar

preserve
	duplicates drop yrsnocivilwar, force 
	list yrs _*
restore

* Counterfactual #1: mean values of t (inconsistent across t)
preserve
	collapse (median) prevconcessions_l democracy kin (mean) logfactions yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw

	order logfactions prevconcessions_l democracy kin yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw
	
	tempfile cf1
	save `cf1', replace
restore

* Counterfactual #2: mean values of t (consistent across t)
preserve
	collapse (median) prevconcessions_l democracy kin (mean) logfactions yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw

	replace yrsnocivilwar = 15
	replace _spline1_cw = -1422
	replace _spline2_cw = -2448
	replace _spline3_cw = -1425

	order logfactions prevconcessions_l democracy kin yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw
	
	tempfile cf2
	save `cf2', replace 
restore

* Counterfactual #3: median values of t (consistent across t)
preserve
	collapse (median) prevconcessions_l democracy kin yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw (mean) logfactions 
	
	replace yrsnocivilwar = 10
	replace _spline1_cw = -590.3333
	replace _spline2_cw = -733.3333
	replace _spline3_cw = -422.2222

	order logfactions prevconcessions_l democracy kin yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw
	
	tempfile cf3
	save `cf3', replace 
restore

* Counterfactual #4: modal values of t (consistent across t)
preserve
	collapse (median) prevconcessions_l democracy kin (mean) logfactions yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw
	
	replace yrsnocivilwar = 0
	replace _spline1_cw = 0
	replace _spline2_cw = 0
	replace _spline3_cw = 0

	order logfactions prevconcessions_l democracy kin yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw
	
	tempfile cf4
	save `cf4', replace 
restore

* Counterfactual #5: replication
preserve
	collapse (min) kin (median) prevconcessions_l democracy (mean) logfactions yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw

	order logfactions prevconcessions_l democracy kin yrsnocivilwar _spline1_cw _spline2_cw _spline3_cw
	
	tempfile cf5
	save `cf5', replace
restore

preserve
	use `cf1', clear
	foreach n of numlist 2(1)5 {
		append using `cf`n''
	}
	saveold "Cunningham 2013\Data\Counterfactuals\C_CF.dta", replace version(12)
restore

*****************************************************************
*** Flores-Macias and Kreps (2013, APSR), Table 2, Model 6, page 841
*****************************************************************
use "Flores-Macias and Kreps 2013\Flores-MaciasKrepsAPSR.dta", clear

logit taxdummy party divided electionyear mid_sidea lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp type severity yearsnotax cubicspline1 cubicspline2 cubicspline3 if severity>3, vce(robust)
keep if e(sample)

keep party divided electionyear mid_sidea lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp type severity yearsnotax cubicspline1 cubicspline2 cubicspline3
order party divided electionyear mid_sidea lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp type severity yearsnotax cubicspline1 cubicspline2 cubicspline3
saveold "Flores-Macias and Kreps 2013\Data\Counterfactuals\FMK.dta", replace version(12)

sum yearsnotax, det
tab yearsnotax

preserve
	duplicates drop yearsnotax, force 
	sort yearsnotax
	list yearsn cub*
restore

* Counterfactual #1: mean values of t (inconsistent across t)
preserve
	collapse (median) mid_sidea electionyear divided type party (mean) lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp severity yearsnotax cubicspline1 cubicspline2 cubicspline3	

	order party divided electionyear mid_sidea lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp type severity yearsnotax cubicspline1 cubicspline2 cubicspline3
	
	tempfile cf1
	save `cf1', replace
restore

* Counterfactual #2: mean value of t (consistent across t)
preserve
	collapse (median) mid_sidea electionyear divided type party (mean) lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp severity yearsnotax cubicspline1 cubicspline2 cubicspline3

	replace yearsnotax = 14
	replace cubicspline1 = 1.38696
	replace cubicspline2 = 0.460216
	replace cubicspline3 = 0.00505

	order party divided electionyear mid_sidea lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp type severity yearsnotax cubicspline1 cubicspline2 cubicspline3
	
	tempfile cf2
	save `cf2', replace 
restore

* Counterfactual #3: median value of t (consistent across t)
preserve
	collapse (median) mid_sidea electionyear divided type party yearsnotax cub* (mean) lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp severity 

	order party divided electionyear mid_sidea lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp type severity yearsnotax cubicspline1 cubicspline2 cubicspline3
	
	tempfile cf3
	save `cf3', replace 
restore

* Counterfactual #4: modal value of t (consistent across t)
preserve
	collapse (median) mid_sidea electionyear divided type party (mean) lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp severity yearsnotax cubicspline1 cubicspline2 cubicspline3
	
	replace yearsnotax = 1
	replace cubicspline1 = 0
	replace cubicspline2 = 0
	replace cubicspline3 = 0

	order party divided electionyear mid_sidea lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp type severity yearsnotax cubicspline1 cubicspline2 cubicspline3
	
	tempfile cf4
	save `cf4', replace 
restore

* Counterfactual #5: replication
preserve
	collapse (median) mid_sidea electionyear divided type party (mean) lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp severity yearsnotax cubicspline1 cubicspline2 cubicspline3	
	replace severity = 0
	
	order party divided electionyear mid_sidea lagdebtgdp laginflationrate laggdpgrowth lagPerChangeDefExp type severity yearsnotax cubicspline1 cubicspline2 cubicspline3
	
	tempfile cf5
	save `cf5', replace
restore

preserve
	use `cf1', clear
	foreach n of numlist 2(1)5 {
		append using `cf`n''
	}
	saveold "Flores-Macias and Kreps 2013\Data\Counterfactuals\FMK_CF.dta", replace version(12)
restore

